﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using Xunit;
using YAPL.Language.SourceParser;
using YAPL.Language.Ast;
using YAPL.Language.SourceParser.XML;

namespace YAPL.Test.YAPL.Language.Parser.XML.NodeParsers {
	public class XmlReturnParserTest : XmlNodeParserTest {

		[Fact]
		public void ReturnNodeShouldNotBeEmpty() {
			var returnNode = new XElement(XmlNames.ReturnExpression);
			Assert.Throws<ArgumentException>(() => _parser.ParseNode(returnNode));
		}

		[Fact]
		public void ReturnLiteralShouldBeParsedCorrectly() {
			var returnNode = new XElement(XmlNames.ReturnExpression,
				new XElement(XmlNames.ConstantExpression, new XAttribute(XmlNames.ConstantValueAttribute, "'literal'")));
			var expr = _parser.ParseNode(returnNode);
			Assert.IsType(typeof(ReturnExpression),expr);
			var returnExpr = (ReturnExpression) expr;
			Assert.IsType(typeof(ConstantExpression), returnExpr.Statement);
			var returnConstant = (ConstantExpression) returnExpr.Statement;
			Assert.IsType(typeof(string), returnConstant.Value);
			Assert.Equal("literal", returnConstant.Value);
		}
	}
}